/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI.NVGH;

import DAO.HoaDonDao;
import DAO.KhachHangDao;
import GUI.MainForm;
import GUI.NVGH.frCapNhatTrangThaiHoaDon;
import GUI.NVK.frKhaNangCungUng;
import GUI.Var;
import POJO.HoaDon;
import POJO.KhachHang;
import java.beans.PropertyVetoException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Kim
 */
public class frXemThongTinKhachHang extends javax.swing.JInternalFrame {

	private DefaultTableModel tbmodel1;
	private DefaultTableModel tbmodel2;
	private DefaultTableModel tbmodelShow;

	/**
	 * Creates new form frXemThongTinKhachHang
	 */
	public frXemThongTinKhachHang() {
		initComponents();
		timKiemVaHienThi();
		jbtnHienThi1.setVisible(false);
	}

	public void DefaultFormKhachHang() {
		tbmodel1 = new DefaultTableModel();
		tbmodelShow = new DefaultTableModel();

		//tạo các cột
		this.tbmodel1.addColumn("STT ");
		this.tbmodel1.addColumn("Mã KH");
		this.tbmodel1.addColumn("Tên khách hàng");
		this.tbmodel1.addColumn("Địa chỉ");
		this.tbmodel1.addColumn("Điện thoại");

		this.tbmodelShow.addColumn("STT ");
		this.tbmodelShow.addColumn("Mã KH");
		this.tbmodelShow.addColumn("Tên khách hàng");
		this.tbmodelShow.addColumn("Điện thoại");

		jtDSKhachHang.setModel(tbmodelShow);
		int[] va = {10, 10, 40, 40};
		int[] pt = new int[4];
		for (int l = 0; l < 4; l++) {
			pt[l] = jtDSKhachHang.getWidth() * va[l] / 100;
			jtDSKhachHang.getColumnModel().getColumn(l).setPreferredWidth(pt[l]);

		}
	}

	public void DefaultFormHoaDon() {
		tbmodel2 = new DefaultTableModel();
		//tạo các cột
		this.tbmodel2.addColumn("STT ");
		this.tbmodel2.addColumn("Mã hoá đơn");
		this.tbmodel2.addColumn("Ngày lập");
		
		jtDSKhachHang1.setModel(tbmodel2);
		int[] va = {20, 40, 40};
		int[] pt = new int[3];
		for (int l = 0; l < 3; l++) {
			pt[l] = jtDSKhachHang1.getWidth() * va[l] / 100;
			jtDSKhachHang1.getColumnModel().getColumn(l).setPreferredWidth(pt[l]);

		}
	}

	public void LoadHoaDon(int maKH) {
		DefaultFormHoaDon();
		ArrayList<HoaDon> dsHoaDon = HoaDonDao.layByMaKH(maKH);
		int i = 1;
		for (HoaDon hd : dsHoaDon) {
			Object[] items = new Object[]{
				i,
				hd.getMaHD(),
				Var.hienThiNgayVN(hd.getNgayLap())
			};
			i++;
			//int maLSP = sp.getMaLSP();
			tbmodel2.addRow(items);
		}
		
	}

	public String KiemTraMa() {
		String str = "";
		if (jtfMaKH.getText().equals("")) {
			str += "- Chưa nhập mã khách hàng ! \r\n";
		}
		return str;
	}

	public String KiemTraTen() {
		String str = "";
		if (jtfTenKH.getText().equals("")) {
			str += "- Chưa nhập tên khách hàng ! \r\n";
		}
		return str;
	}

	public String KiemTraDiaChi() {
		String str = "";
		if (jtfDiaChi.getText().equals("")) {
			str += "- Chưa nhập địa chỉ ! \r\n";
		}
		return str;
	}

	public String KiemTraDienThoai() {
		String str = "";
		if (jtfSoDienThoai.getText().equals("")) {
			str += "- Chưa nhập số điện thoại ! \r\n";
		}
		return str;
	}

	/**
	 * This method is called from within the constructor to initialize the
	 * form. WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
       // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
       private void initComponents() {

              jPanel4 = new javax.swing.JPanel();
              jLabel5 = new javax.swing.JLabel();
              jPanel1 = new javax.swing.JPanel();
              jtfMaKH = new javax.swing.JTextField();
              jtfTenKH = new javax.swing.JTextField();
              jLabel1 = new javax.swing.JLabel();
              jLabel2 = new javax.swing.JLabel();
              jLabel3 = new javax.swing.JLabel();
              jtfDiaChi = new javax.swing.JTextField();
              jLabel4 = new javax.swing.JLabel();
              jtfSoDienThoai = new javax.swing.JTextField();
              jPanel2 = new javax.swing.JPanel();
              jbtnSua = new javax.swing.JButton();
              jbtnHienThi = new javax.swing.JButton();
              jbtnHienThi1 = new javax.swing.JButton();
              jPanel6 = new javax.swing.JPanel();
              jPanel5 = new javax.swing.JPanel();
              jScrollPane3 = new javax.swing.JScrollPane();
              jtDSKhachHang1 = new javax.swing.JTable();
              jPanel3 = new javax.swing.JPanel();
              jScrollPane1 = new javax.swing.JScrollPane();
              jtDSKhachHang = new javax.swing.JTable();

              setClosable(true);
              setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
              setIconifiable(true);
              setMaximizable(true);
              setResizable(true);

              jLabel5.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
              jLabel5.setText("XEM THÔNG TIN KHÁCH HÀNG");

              javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
              jPanel4.setLayout(jPanel4Layout);
              jPanel4Layout.setHorizontalGroup(
                     jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                            .addContainerGap(161, Short.MAX_VALUE)
                            .addComponent(jLabel5)
                            .addContainerGap(161, Short.MAX_VALUE))
              );
              jPanel4Layout.setVerticalGroup(
                     jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(jPanel4Layout.createSequentialGroup()
                            .addGap(0, 0, 0)
                            .addComponent(jLabel5)
                            .addGap(0, 0, Short.MAX_VALUE))
              );

              jtfMaKH.setText("0");

              jtfTenKH.addActionListener(new java.awt.event.ActionListener() {
                     public void actionPerformed(java.awt.event.ActionEvent evt) {
                            jtfTenKHActionPerformed(evt);
                     }
              });
              jtfTenKH.addInputMethodListener(new java.awt.event.InputMethodListener() {
                     public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
                     }
                     public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
                            jtfTenKHInputMethodTextChanged(evt);
                     }
              });
              jtfTenKH.addKeyListener(new java.awt.event.KeyAdapter() {
                     public void keyReleased(java.awt.event.KeyEvent evt) {
                            jtfTenKHKeyReleased(evt);
                     }
              });
              jtfTenKH.addVetoableChangeListener(new java.beans.VetoableChangeListener() {
                     public void vetoableChange(java.beans.PropertyChangeEvent evt)throws java.beans.PropertyVetoException {
                            jtfTenKHVetoableChange(evt);
                     }
              });

              jLabel1.setText("Mã khách hàng:");

              jLabel2.setText("Tên khách hàng:");

              jLabel3.setText("Địa chỉ:");

              jtfDiaChi.addActionListener(new java.awt.event.ActionListener() {
                     public void actionPerformed(java.awt.event.ActionEvent evt) {
                            jtfDiaChiActionPerformed(evt);
                     }
              });
              jtfDiaChi.addInputMethodListener(new java.awt.event.InputMethodListener() {
                     public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
                     }
                     public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
                            jtfDiaChiInputMethodTextChanged(evt);
                     }
              });
              jtfDiaChi.addKeyListener(new java.awt.event.KeyAdapter() {
                     public void keyReleased(java.awt.event.KeyEvent evt) {
                            jtfDiaChiKeyReleased(evt);
                     }
              });
              jtfDiaChi.addVetoableChangeListener(new java.beans.VetoableChangeListener() {
                     public void vetoableChange(java.beans.PropertyChangeEvent evt)throws java.beans.PropertyVetoException {
                            jtfDiaChiVetoableChange(evt);
                     }
              });

              jLabel4.setText("Số điện thoại:");

              jtfSoDienThoai.addActionListener(new java.awt.event.ActionListener() {
                     public void actionPerformed(java.awt.event.ActionEvent evt) {
                            jtfSoDienThoaiActionPerformed(evt);
                     }
              });
              jtfSoDienThoai.addInputMethodListener(new java.awt.event.InputMethodListener() {
                     public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
                     }
                     public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
                            jtfSoDienThoaiInputMethodTextChanged(evt);
                     }
              });
              jtfSoDienThoai.addKeyListener(new java.awt.event.KeyAdapter() {
                     public void keyReleased(java.awt.event.KeyEvent evt) {
                            jtfSoDienThoaiKeyReleased(evt);
                     }
              });
              jtfSoDienThoai.addVetoableChangeListener(new java.beans.VetoableChangeListener() {
                     public void vetoableChange(java.beans.PropertyChangeEvent evt)throws java.beans.PropertyVetoException {
                            jtfSoDienThoaiVetoableChange(evt);
                     }
              });

              javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
              jPanel1.setLayout(jPanel1Layout);
              jPanel1Layout.setHorizontalGroup(
                     jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                            .addGap(118, 118, 118)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                   .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING)
                                   .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING)
                                   .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING)
                                   .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.TRAILING))
                            .addGap(30, 30, 30)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                   .addComponent(jtfMaKH, javax.swing.GroupLayout.Alignment.TRAILING)
                                   .addComponent(jtfTenKH, javax.swing.GroupLayout.Alignment.TRAILING)
                                   .addComponent(jtfDiaChi, javax.swing.GroupLayout.Alignment.TRAILING)
                                   .addComponent(jtfSoDienThoai, javax.swing.GroupLayout.Alignment.TRAILING))
                            .addContainerGap())
              );
              jPanel1Layout.setVerticalGroup(
                     jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(jPanel1Layout.createSequentialGroup()
                            .addContainerGap()
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                   .addComponent(jtfMaKH, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                   .addComponent(jLabel1))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                   .addComponent(jtfTenKH, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                   .addComponent(jLabel2))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                   .addComponent(jtfDiaChi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                   .addComponent(jLabel3))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                   .addComponent(jtfSoDienThoai, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                   .addComponent(jLabel4))
                            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
              );

              jbtnSua.setText("Sửa");
              jbtnSua.addActionListener(new java.awt.event.ActionListener() {
                     public void actionPerformed(java.awt.event.ActionEvent evt) {
                            jbtnSuaActionPerformed(evt);
                     }
              });

              jbtnHienThi.setText("Tìm");
              jbtnHienThi.addActionListener(new java.awt.event.ActionListener() {
                     public void actionPerformed(java.awt.event.ActionEvent evt) {
                            jbtnHienThiActionPerformed(evt);
                     }
              });

              jbtnHienThi1.setText("Xem hóa đơn");
              jbtnHienThi1.setToolTipText("Cập nhật trạng thái hóa đơn");
              jbtnHienThi1.addActionListener(new java.awt.event.ActionListener() {
                     public void actionPerformed(java.awt.event.ActionEvent evt) {
                            jbtnHienThi1ActionPerformed(evt);
                     }
              });

              javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
              jPanel2.setLayout(jPanel2Layout);
              jPanel2Layout.setHorizontalGroup(
                     jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jbtnSua)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jbtnHienThi)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jbtnHienThi1)
                            .addGap(101, 101, 101))
              );
              jPanel2Layout.setVerticalGroup(
                     jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                            .addGap(0, 0, Short.MAX_VALUE)
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                   .addComponent(jbtnSua)
                                   .addComponent(jbtnHienThi)
                                   .addComponent(jbtnHienThi1))
                            .addGap(0, 0, 0))
              );

              jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Danh sách mã hóa đơn"));

              jtDSKhachHang1.setModel(new javax.swing.table.DefaultTableModel(
                     new Object [][] {

                     },
                     new String [] {
                            "STT", "Mã hóa đơn", "Ngày lập"
                     }
              ));
              jtDSKhachHang1.addMouseListener(new java.awt.event.MouseAdapter() {
                     public void mouseClicked(java.awt.event.MouseEvent evt) {
                            jtDSKhachHang1MouseClicked(evt);
                     }
              });
              jScrollPane3.setViewportView(jtDSKhachHang1);

              javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
              jPanel5.setLayout(jPanel5Layout);
              jPanel5Layout.setHorizontalGroup(
                     jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
              );
              jPanel5Layout.setVerticalGroup(
                     jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addComponent(jScrollPane3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 260, Short.MAX_VALUE)
              );

              jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Danh sách khách hàng"));

              jtDSKhachHang.setModel(new javax.swing.table.DefaultTableModel(
                     new Object [][] {

                     },
                     new String [] {
                            "STT", "Mã khách hàng", "Tên khách hàng", "Điện thoại"
                     }
              ));
              jtDSKhachHang.addMouseListener(new java.awt.event.MouseAdapter() {
                     public void mouseClicked(java.awt.event.MouseEvent evt) {
                            jtDSKhachHangMouseClicked(evt);
                     }
              });
              jScrollPane1.setViewportView(jtDSKhachHang);

              javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
              jPanel3.setLayout(jPanel3Layout);
              jPanel3Layout.setHorizontalGroup(
                     jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
              );
              jPanel3Layout.setVerticalGroup(
                     jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 272, Short.MAX_VALUE)
              );

              javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
              jPanel6.setLayout(jPanel6Layout);
              jPanel6Layout.setHorizontalGroup(
                     jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
                            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGap(0, 0, 0)
                            .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGap(0, 0, 0))
              );
              jPanel6Layout.setVerticalGroup(
                     jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(jPanel6Layout.createSequentialGroup()
                            .addContainerGap()
                            .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                   .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                   .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
              );

              javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
              getContentPane().setLayout(layout);
              layout.setHorizontalGroup(
                     layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addGap(0, 0, 0)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                   .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                   .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                   .addComponent(jPanel4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                   .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGap(0, 0, 0))
              );
              layout.setVerticalGroup(
                     layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(layout.createSequentialGroup()
                            .addGap(0, 0, 0)
                            .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(0, 0, 0)
                            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(0, 0, 0)
                            .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(0, 0, 0)
                            .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGap(0, 0, 0))
              );

              pack();
       }// </editor-fold>//GEN-END:initComponents

       private void jtfTenKHActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtfTenKHActionPerformed
		// TODO add your handling code here:
       }//GEN-LAST:event_jtfTenKHActionPerformed

       private void jtfTenKHInputMethodTextChanged(java.awt.event.InputMethodEvent evt) {//GEN-FIRST:event_jtfTenKHInputMethodTextChanged
		// TODO add your handling code here:
       }//GEN-LAST:event_jtfTenKHInputMethodTextChanged

       private void jtfTenKHKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfTenKHKeyReleased
		// TODO add your handling code here:
		//       vbtSua();
       }//GEN-LAST:event_jtfTenKHKeyReleased

       private void jtfTenKHVetoableChange(java.beans.PropertyChangeEvent evt)throws java.beans.PropertyVetoException {//GEN-FIRST:event_jtfTenKHVetoableChange
		// TODO add your handling code here:
       }//GEN-LAST:event_jtfTenKHVetoableChange

       private void jtfDiaChiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtfDiaChiActionPerformed
		// TODO add your handling code here:
       }//GEN-LAST:event_jtfDiaChiActionPerformed

       private void jtfDiaChiInputMethodTextChanged(java.awt.event.InputMethodEvent evt) {//GEN-FIRST:event_jtfDiaChiInputMethodTextChanged
		// TODO add your handling code here:
       }//GEN-LAST:event_jtfDiaChiInputMethodTextChanged

       private void jtfDiaChiKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfDiaChiKeyReleased
		// TODO add your handling code here:
       }//GEN-LAST:event_jtfDiaChiKeyReleased

       private void jtfDiaChiVetoableChange(java.beans.PropertyChangeEvent evt)throws java.beans.PropertyVetoException {//GEN-FIRST:event_jtfDiaChiVetoableChange
		// TODO add your handling code here:
       }//GEN-LAST:event_jtfDiaChiVetoableChange

       private void jtfSoDienThoaiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtfSoDienThoaiActionPerformed
		// TODO add your handling code here:
       }//GEN-LAST:event_jtfSoDienThoaiActionPerformed

       private void jtfSoDienThoaiInputMethodTextChanged(java.awt.event.InputMethodEvent evt) {//GEN-FIRST:event_jtfSoDienThoaiInputMethodTextChanged
		// TODO add your handling code here:
       }//GEN-LAST:event_jtfSoDienThoaiInputMethodTextChanged

       private void jtfSoDienThoaiKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfSoDienThoaiKeyReleased
		// TODO add your handling code here:
       }//GEN-LAST:event_jtfSoDienThoaiKeyReleased

       private void jtfSoDienThoaiVetoableChange(java.beans.PropertyChangeEvent evt)throws java.beans.PropertyVetoException {//GEN-FIRST:event_jtfSoDienThoaiVetoableChange
		// TODO add your handling code here:
       }//GEN-LAST:event_jtfSoDienThoaiVetoableChange

       private void jbtnSuaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnSuaActionPerformed
		// TODO add your handling code here:
		String kt = "";
		if (kt == KiemTraMa()) {
			if (kt == "") {
				if (kt == KiemTraTen() || kt == KiemTraDiaChi() || kt == KiemTraDienThoai()) {
					if (kt == "") {
						int maKH = Integer.parseInt(this.jtfMaKH.getText());
						String TenKH = this.jtfTenKH.getText();
						String DiaChi = this.jtfDiaChi.getText();
						String DienThoai = this.jtfSoDienThoai.getText();

						KhachHang kh = new KhachHang();

						kh.setMaKH(maKH);
						kh.setTenKH(TenKH);
						kh.setDiaChi(DiaChi);
						kh.setDienThoai(DienThoai);

						boolean kq = KhachHangDao.capNhat(kh);
						if (kq == true) {
							JOptionPane.showMessageDialog(this, "Cập nhật khách hàng thành công", "Thông báo", JOptionPane.INFORMATION_MESSAGE);
							timKiemVaHienThi();
						} else {
							JOptionPane.showMessageDialog(this, "Cập nhật khách hàng thất bại", "Cảnh báo!!!", JOptionPane.WARNING_MESSAGE);
						}
					} else {
						JOptionPane.showMessageDialog(this, "Vui lòng nhập thông tin để cập nhật!", "Cảnh báo!!!", JOptionPane.INFORMATION_MESSAGE);
					}
				}
			}
		} else {
			JOptionPane.showMessageDialog(this, "Vui lòng chọn khách hàng cần cập nhật thông tin!", "Cảnh báo!!!", JOptionPane.INFORMATION_MESSAGE);
		}
       }//GEN-LAST:event_jbtnSuaActionPerformed
	private KhachHang setKhachHang() {
		int ma = 0;
		if (!jtfMaKH.getText().trim().equals("")) {
			try {
				ma = Integer.parseInt(this.jtfMaKH.getText().trim());

			} catch (NumberFormatException e) {
				JOptionPane.showMessageDialog(this, "Lỗi nhập số", "Thông báo lỗi", JOptionPane.ERROR_MESSAGE);
				jtfMaKH.requestFocus();
				return null;
			}
		}

		String TenKH = this.jtfTenKH.getText().trim();
		String DiaChi = this.jtfDiaChi.getText().trim();
		String DienThoai = this.jtfSoDienThoai.getText().trim();

		KhachHang kh = new KhachHang();
		kh.setMaKH(ma);
		kh.setTenKH(TenKH);
		kh.setDiaChi(DiaChi);
		kh.setDienThoai(DienThoai);
		return kh;
	}

	private void timKiemVaHienThi() {
		KhachHang kh = new KhachHang();

		kh = setKhachHang();
		if (kh == null) {
			return;
		}
		KhachHangDao dao = new KhachHangDao();

		ArrayList<KhachHang> dskh = new ArrayList<KhachHang>();

		try {
			tbmodel1 = new DefaultTableModel();
			DefaultFormKhachHang();
			dskh = dao.timKiem(kh);
			int i = 1;
			for (KhachHang kh1 : dskh) {
				Object[] items = new Object[]{
					kh1.getMaKH(),
					kh1.getTenKH(),
					kh1.getDiaChi(),
					kh1.getDienThoai()
				};
				Object[] items2 = new Object[]{
					i,
					kh1.getMaKH(),
					kh1.getTenKH(),
					kh1.getDienThoai()
				};
				i++;
				//int maLSP = sp.getMaLSP();
				tbmodelShow.addRow(items2);
				tbmodel1.addRow(items);

			}

			if (tbmodel1.getRowCount() > 0) {
				loadText(0);
			}

		} catch (Exception e) {
			JOptionPane.showMessageDialog(this, "Không tìm thấy");
		}

	}
       private void jbtnHienThiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnHienThiActionPerformed
		// TODO add your handling code here:
		timKiemVaHienThi();
		jbtnHienThi1.setVisible(false);
       }//GEN-LAST:event_jbtnHienThiActionPerformed

       private void jbtnHienThi1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnHienThi1ActionPerformed
		// TODO add your handling code here:
		frCapNhatTrangThaiHoaDon fr = new frCapNhatTrangThaiHoaDon();
		fr.setVisible(true);
		MainForm.jDesktopPane1.add(fr);
		int dong = jtDSKhachHang1.getSelectedRow();
		String mahd = tbmodel2.getValueAt(dong, 1).toString();
		fr.jtxtMaHD.setText(mahd);
		fr.tim();
		try {
			fr.setSelected(isSelected);
		} catch (PropertyVetoException ex) {
			Logger.getLogger(frXemThongTinKhachHang.class.getName()).log(Level.SEVERE, null, ex);
		}
       }//GEN-LAST:event_jbtnHienThi1ActionPerformed
	private void loadText(int dong) {

		int maKH = Integer.parseInt(this.tbmodel1.getValueAt(dong, 0).toString());
		String tenKH = (String) this.tbmodel1.getValueAt(dong, 1).toString();
		String diaChi = this.tbmodel1.getValueAt(dong, 2).toString();
		String dienThoai = this.tbmodel1.getValueAt(dong, 3).toString();

		jtfMaKH.setText(String.valueOf(maKH));
		jtfTenKH.setText(tenKH);
		jtfDiaChi.setText(String.valueOf(diaChi));
		jtfSoDienThoai.setText(String.valueOf(dienThoai));
		LoadHoaDon(maKH);
	}
       private void jtDSKhachHangMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jtDSKhachHangMouseClicked
		// TODO add your handling code here:
		int dong = this.jtDSKhachHang.getSelectedRow();

		loadText(dong);
		if (tbmodel2.getRowCount() == 0) {
			jbtnHienThi1.setVisible(false);
		}
       }//GEN-LAST:event_jtDSKhachHangMouseClicked

       private void jtDSKhachHang1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jtDSKhachHang1MouseClicked
		// TODO add your handling code here:
		jbtnHienThi1.setVisible(true);
       }//GEN-LAST:event_jtDSKhachHang1MouseClicked
       // Variables declaration - do not modify//GEN-BEGIN:variables
       private javax.swing.JLabel jLabel1;
       private javax.swing.JLabel jLabel2;
       private javax.swing.JLabel jLabel3;
       private javax.swing.JLabel jLabel4;
       private javax.swing.JLabel jLabel5;
       private javax.swing.JPanel jPanel1;
       private javax.swing.JPanel jPanel2;
       private javax.swing.JPanel jPanel3;
       private javax.swing.JPanel jPanel4;
       private javax.swing.JPanel jPanel5;
       private javax.swing.JPanel jPanel6;
       private javax.swing.JScrollPane jScrollPane1;
       private javax.swing.JScrollPane jScrollPane3;
       private javax.swing.JButton jbtnHienThi;
       private javax.swing.JButton jbtnHienThi1;
       private javax.swing.JButton jbtnSua;
       private javax.swing.JTable jtDSKhachHang;
       private javax.swing.JTable jtDSKhachHang1;
       private javax.swing.JTextField jtfDiaChi;
       private javax.swing.JTextField jtfMaKH;
       private javax.swing.JTextField jtfSoDienThoai;
       private javax.swing.JTextField jtfTenKH;
       // End of variables declaration//GEN-END:variables
}
